﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using Ivony.Html;
using Ivony.Html.Parser;

namespace ZX.EHR.ResumeParseLib
{
    /// <summary>
    /// 中国人才热线
    /// </summary>
    public class CjolParsing : IHtmlParsable
    {
        public ResumeParsedInfo Parsing(string htmlContent)
        {
            if (string.IsNullOrEmpty(htmlContent))
                throw new ArgumentNullException("htmlContent");

            ResumeParsedInfo resumeInfo = null;
            var doc = new JumonyParser().Parse(htmlContent);
            if (doc != null)
            {
                if (doc.Find("IMG").Count() > 0)
                {
                    var att = doc.Find("IMG").ElementAt(0).Attribute("src");
                    if (att != null)
                    {
                        if (true == att.AttributeValue.Contains("cjol.com") || true == att.AttributeValue.Contains("cjolimg.com"))
                        {
                            resumeInfo = new ResumeParsedInfo();
                            resumeInfo.Name = doc.Find(".fieldContent").ElementAt(0).InnerText();//姓名
                            resumeInfo.Gender = doc.Find(".fieldContent").ElementAt(1).InnerText();//性别
                            resumeInfo.BirthDay = doc.Find(".fieldContent").ElementAt(3).InnerText();//出生日期
                            resumeInfo.WorkYears = doc.Find(".fieldContent").ElementAt(8).InnerText().Split('年')[0];//工作年限
                            resumeInfo.Degree = doc.Find(".fieldContent").ElementAt(14).InnerText();//学历
                            resumeInfo.NowPosition = doc.Find(".fieldContent").ElementAt(16).InnerText();//目前岗位
                            resumeInfo.ApplyPosition = doc.Find(".fieldName").ElementAt(0).InnerText();//申请岗位
                            resumeInfo.PhoneNO = doc.Find(".fieldContent").ElementAt(26).InnerText(); //手机
                            resumeInfo.Email = doc.Find(".fieldContent").ElementAt(29).InnerText();//EMAIL
                            resumeInfo.FullHtmlContent = htmlContent;
                        }
                    }
                    else
                    {
                        throw new ApplicationException("请检查您上传的是否中国人才热线的简历");
                    }
                }
                else
                {
                    throw new ApplicationException("无法识别的简历类型");
                }
            }
            return resumeInfo;
        }
    }
}
